package day08._StuSystem;

import java.util.ArrayList;
import java.util.Scanner;

public class Project {
    public static void main(String[] args) {
        boolean ifexit = false;
        Scanner sc = new Scanner(System.in);
        ArrayList<StuBean> StuInf = new ArrayList<>();
        while (!ifexit) {
            System.out.print("_______________欢迎来到学生管理系统_______________\n1：添加学生\n2：删除学生\n3：修改学生\n4：查询学生\n5：退出\n请输入您的选择：");
            int choose=sc.nextInt();
            switch (choose) {
                case 1->StuInf=AddStu(StuInf);
                case 2->StuInf=DelStu(StuInf);
                case 3->StuInf=ModStu(StuInf);
                case 4->StuInf=QueStu(StuInf);
                case 5->ifexit=true;
                default->System.out.println("命令非法！");
            }
        }
    }

    public static ArrayList<StuBean> AddStu(ArrayList<StuBean> Stu) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要添加的学生id：");
        int id=sc.nextInt();
        for(int i=0;i<Stu.size();i++){
            if(Stu.get(i).getId()==id){
                System.out.println("该学生id已存在！");
                return Stu;
            }
        }
        System.out.println("请输入该学生的姓名：");
        String name=sc.next();
        System.out.println("请输入该学生的年龄：");
        int age=sc.nextInt();
        System.out.println("请输入该学生的家庭地址：");
        String address=sc.next();
        Stu.add(new StuBean(id,name,age,address));
        return Stu;
    }

    public static ArrayList<StuBean> DelStu(ArrayList<StuBean> Stu) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要删除的学生id：");
        int id=sc.nextInt();
        for(int i=0;i<Stu.size();i++){
            if(Stu.get(i).getId()==id){
                Stu.remove(i);
                return Stu;
            }
        }
        System.out.println("该学生不存在！");
        return Stu;
    }

    public static ArrayList<StuBean> ModStu(ArrayList<StuBean> Stu) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要修改的学生id：");
        int id=sc.nextInt();
        for(int i=0;i<Stu.size();i++){
            if(Stu.get(i).getId()==id){
                System.out.println("请输入该学生的id：");
                int newId=sc.nextInt();
                System.out.println("请输入该学生的姓名：");
                String name=sc.next();
                System.out.println("请输入该学生的年龄：");
                int age=sc.nextInt();
                System.out.println("请输入该学生的家庭地址：");
                String address=sc.next();
                Stu.set(i, new StuBean(newId,name,age,address));
                return Stu;
            }
        }
        System.out.println("该学生不存在！");
        return Stu;
    }

    public static ArrayList<StuBean> QueStu(ArrayList<StuBean> Stu) {
        if(Stu.size()==0){System.out.println("当前无学生信息，请添加后查询。");}
        for(int i=0;i<Stu.size();i++){
            System.out.println(Stu.get(i).getId());
            System.out.println(Stu.get(i).getName());
            System.out.println(Stu.get(i).getAge());
            System.out.println(Stu.get(i).getAddress());
        }
        return Stu;
    }

}
